{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "import os\n",
    "from functools import reduce\n",
    "from fal.dbt.integration.magics import init_fal\n",
    "from fal.dbt.typing import *\n",
    "%init_fal project_dir=../.. profiles_dir=../../.. default_model_name=model_e_notebook"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Get the models"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df = ref(\"model_c\")"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Add the new data"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "df[\"my_null\"] = None"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Write back to data warehouse"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "write_to_model(df)"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "# Leave behind an artifact for tests"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": [
    "model_name = context.current_model.name\n",
    "\n",
    "output = f\"Model name: {model_name}\"\n",
    "output = output + f\"\\nStatus: {context.current_model.status}\"\n",
    "\n",
    "output = output + \"\\nModel dataframe name: {model_name}\"\n",
    "temp_dir = os.environ[\"temp_dir\"]\n",
    "\n",
    "write_dir = open(reduce(os.path.join, [temp_dir, model_name + \".txt\"]), \"w\")\n",
    "write_dir.write(output)\n",
    "write_dir.close()"
   ]
  }
 ],
 "metadata": {
  "language_info": {
   "name": "python"
  },
  "orig_nbformat": 4
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
